package com.pmh.hrs.sys.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.pmh.hrs.sys.service.SysMenuService;

@Controller
@RequestMapping("/sys/menus")
public class SysMenuController {
	
	@Resource(name="sysMenuService")
	private SysMenuService sysMenuService;
	
	/**
	 * 메뉴추가 
	 * @param paramMap
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(method =RequestMethod.POST)
	@ResponseStatus(HttpStatus.CREATED)
	public @ResponseBody Map<String,Object> insert( @RequestBody Map<String,Object> paramMap,HttpServletRequest request) throws Exception{
		
		Map<String,Object> ajaxData = new HashMap<String,Object>();
		sysMenuService.insert(paramMap);
		
		//List<Map<String,?>> storeUserMst =systemService.select(paramMap);
	//	ajaxData.put("UserInfoMst", storeUserMst);
		return ajaxData;
	}
	/**
	 * 메뉴수정 
	 * @param paramMap
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(method =RequestMethod.PUT)
	public @ResponseBody Map<String,Object> update( @RequestBody Map<String,Object> paramMap,HttpServletRequest request) throws Exception{
		
		Map<String,Object> ajaxData = new HashMap<String,Object>();
		sysMenuService.update(paramMap);
		
		//List<Map<String,?>> storeUserMst =systemService.select(paramMap);
	//	ajaxData.put("UserInfoMst", storeUserMst);
		return ajaxData;
	}
	
	@RequestMapping(value="/open/{lvl}",method =RequestMethod.GET)
	public @ResponseBody Map<String,Object> openMenu( 
			@RequestParam(value ="SYSTEM",required=false) String system,
			@PathVariable("lvl") String lvl,
			@RequestParam(value ="SCREEN_ID",required=false) String screenId,
			HttpServletRequest request) throws Exception{
		Map<String,Object> paramMap = new HashMap<String,Object>();
		Map<String,Object> ajaxData = new HashMap<String,Object>();
		
		paramMap.put("SYSTEM", system);
		paramMap.put("SCREEN_ID", screenId);
		paramMap.put("LVL", lvl);
		
		List<Map<String,Object>> storeSysMenu = sysMenuService.selectList(paramMap);
		ajaxData.put("SYS_MENU", storeSysMenu);
		return ajaxData;
	}
	
	
	
	/**
	 *  메뉴조회 
	 * @param company 회사코드 
	 * @param system  시스템코드 
	 * @param authCd 권한코드
	 * @param screenId 화면ID
	 * @param lvl 화면 레벨
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(method =RequestMethod.GET)
	public @ResponseBody Map<String,Object> selectList( 
			@RequestParam(value ="COMPANY",required=false) String company,
			@RequestParam(value ="SYSTEM",required=false) String system,
			@RequestParam(value ="AUTH_CD",required=false) String authCd,
			@RequestParam(value ="SCREEN_ID",required=false) String screenId,
			@RequestParam(value ="LVL",required=false) String lvl,
			HttpServletRequest request) throws Exception{
		Map<String,Object> paramMap = new HashMap<String,Object>();
		Map<String,Object> ajaxData = new HashMap<String,Object>();
		
		paramMap.put("SYSTEM", system);
		paramMap.put("AUTH_CD", authCd);
		paramMap.put("SCREEN_ID", screenId);
		paramMap.put("LVL", lvl);
		
		List<Map<String,Object>> storeSysMenu = sysMenuService.selectList(paramMap);
		ajaxData.put("SYS_MENU", storeSysMenu);
		return ajaxData;
	}
	
	/**
	 *  메뉴삭제
	 * @param paramMap
	 * @param system
	 * @param screenId
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(method =RequestMethod.DELETE)
	public @ResponseBody Map<String,Object> delete( @RequestBody Map<String,Object> paramMap,
			@RequestParam(value ="SYSTEM") String system,
			@RequestParam(value ="SCREEN_ID") String screenId,
			HttpServletRequest request) throws Exception{
		
		Map<String,Object> ajaxData = new HashMap<String,Object>();
		
			sysMenuService.delete(paramMap);
		
		//List<Map<String,?>> storeUserMst =systemService.select(paramMap);
	//	ajaxData.put("UserInfoMst", storeUserMst);
		return ajaxData;
	}
}
